package com.csu.cphone.controller.admin;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.csu.common.vo.ResultVo;
import com.csu.cphone.pojo.RecycleProblemSelectPojo;
import com.csu.cphone.service.RecycleProblemSelectService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;


/** 
 * @项目名称：cphone
 * @类名称：RecycleProblemSelectManager
 * @类描述：
 * @创建人：Tangc
 * @创建时间：2017年12月3日 下午10:31:52
 * @company:
 */
@Controller
@RequestMapping("admin/recycle/select")
@Api(value = "admin", description = "管理后台")
public class RecycleProblemSelectManager
{
    @Autowired
    private RecycleProblemSelectService problemSelectService;

    @ResponseBody
    @ApiOperation(value = "添加", notes = "添加数据")
    @RequestMapping(value = "/add", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/json; charset=utf-8" })
    public ResultVo<RecycleProblemSelectPojo> add(HttpServletRequest request, HttpServletResponse response,
            @ApiParam(value = "问题类型id") @RequestParam(value = "problemId", required = true) Integer problemId,
            @ApiParam(value = "问题选项") @RequestParam(value = "problemItem", required = true) String problemItem,
            @ApiParam(value = "回收价格") @RequestParam(value = "cost", required = true) Double cost)
    {

        ResultVo<RecycleProblemSelectPojo> resultVo = new ResultVo<RecycleProblemSelectPojo>();
        // 添加
        RecycleProblemSelectPojo result = problemSelectService.add(problemId, problemItem, cost);
        resultVo.setData(result);

        return resultVo;
    }

    @ResponseBody
    @ApiOperation(value = "更新", notes = "更新数据，返回1成功")
    @RequestMapping(value = "/update", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/json; charset=utf-8" })
    public ResultVo<Integer> update(HttpServletRequest request, HttpServletResponse response,
            @RequestBody RecycleProblemSelectPojo selectPojo)
    {

        ResultVo<Integer> resultVo = new ResultVo<Integer>();
        // 添加
        Integer result = problemSelectService.update(selectPojo);
        resultVo.setData(result);

        return resultVo;
    }

    @ResponseBody
    @ApiOperation(value = "查询", notes = "单个")
    @RequestMapping(value = "/queryById", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/json; charset=utf-8" })
    public ResultVo<RecycleProblemSelectPojo> queryById(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(value = "回收问题选型id") @RequestParam(value = "recycleProblemSelectId", required = true) Integer recycleProblemSelectId)
    {

        ResultVo<RecycleProblemSelectPojo> resultVo = new ResultVo<RecycleProblemSelectPojo>();
        // 添加
        RecycleProblemSelectPojo result = problemSelectService.queryById(recycleProblemSelectId);
        resultVo.setData(result);

        return resultVo;
    }

    @ResponseBody
    @ApiOperation(value = "查询总数", notes = "总数")
    @RequestMapping(value = "/count", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/json; charset=utf-8" })
    public ResultVo<Integer> count(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(value = "回收手机问题id") @RequestParam(value = "recyclePhoneProblemId", required = false) Integer recyclePhoneProblemId)
    {
        ResultVo<Integer> resultVo = new ResultVo<Integer>();
        // 添加
        Integer result = problemSelectService.count(recyclePhoneProblemId);
        resultVo.setData(result);

        return resultVo;
    }

    @ResponseBody
    @ApiOperation(value = "查询列表", notes = "分页")
    @RequestMapping(value = "/queryList", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/json; charset=utf-8" })
    public ResultVo<List<RecycleProblemSelectPojo>> queryList(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(value = "页面大小") @RequestParam(value = "pageSize", required = true) Integer pageSize,
            @ApiParam(value = "开始位置") @RequestParam(value = "startIndex", required = true) Integer startIndex,
            @ApiParam(value = "排序") @RequestParam(value = "order", required = false) String order,
            @ApiParam(value = "回收手机问题id") @RequestParam(value = "recyclePhoneProblemId", required = false) Integer recyclePhoneProblemId)
    {

        ResultVo<List<RecycleProblemSelectPojo>> resultVo = new ResultVo<List<RecycleProblemSelectPojo>>();
        // 添加
        if (!"DESC".equalsIgnoreCase(order))
        {
            order = "ASC";
        }
        List<RecycleProblemSelectPojo> result = problemSelectService.queryList(pageSize, startIndex, order,
                recyclePhoneProblemId);
        resultVo.setData(result);

        return resultVo;
    }

    @ResponseBody
    @ApiOperation(value = "删除", notes = "删除数据")
    @RequestMapping(value = "/delById", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/json; charset=utf-8" })
    public ResultVo<Integer> deleteById(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(value = "回收问题选型id") @RequestParam(value = "recycleProblemSelectId", required = true) Integer recycleProblemSelectId)
    {

        ResultVo<Integer> resultVo = new ResultVo<Integer>();
        // 添加
        Integer result = problemSelectService.deleteById(recycleProblemSelectId);
        resultVo.setData(result);

        return resultVo;
    }
}
